
#include "Interpolation.hpp"

class Function1:public Function {
public:
    double operator() (const double x) const {
        return 1.0/(1.0+x*x);
    }
}f1;


int main(){
    std::cout<<"The Assignment B tests Newton Interpolation."<<std::endl<<std::endl;
    std::vector<double> x1,x2,x3,x4;
    std::vector<double> y1,y2,y3,y4;
    int n;double x;
    n=2;
    for(int i=0;i<=n;i++) {
        x=-5.0+10.0*i/n;
        x1.push_back(x);
        y1.push_back(f1(x));
    }
    n=4;
    for(int i=0;i<=n;i++) {
        x=-5.0+10.0*i/n;
        x2.push_back(x);
        y2.push_back(f1(x));
    }
    n=6;
    for(int i=0;i<=n;i++) {
        x=-5.0+10.0*i/n;
        x3.push_back(x);
        y3.push_back(f1(x));
    }
    n=8;
    for(int i=0;i<=n;i++) {
        x=-5.0+10.0*i/n;
        x4.push_back(x);
        y4.push_back(f1(x));
    }
    Newton p1(x1,y1),p2(x2,y2),p3(x3,y3),p4(x4,y4);
    std::cout<<"n=2 : p="<<p1.getPol();
    std::cout<<"n=4 : p="<<p2.getPol();
    std::cout<<"n=6 : p="<<p3.getPol();
    std::cout<<"n=8 : p="<<p4.getPol();
    std::cout<<std::endl<<"--------------------Test succeeds.--------------------"<<std::endl<<std::endl;
    return 0;
}


